home *** CD-ROM | disk | FTP | other *** search
Oberon Document | 1996-01-05 | 6.9 KB | 223 lines | [oODC/obnF] |
- Documents.StdDocumentDesc
- Documents.DocumentDesc
- Containers.ViewDesc
- Views.ViewDesc
- Stores.StoreDesc
- Documents.ModelDesc
- Containers.ModelDesc
- Models.ModelDesc
- Stores.ElemDesc
- TextViews.StdViewDesc
- TextViews.ViewDesc
- TextModels.StdModelDesc
- TextModels.ModelDesc
- TextModels.AttributesDesc
- Helvetica
- Helvetica
- Helvetica
- MODULE ObxLines;
- IMPORT Domains, Stores, Ports, Models, Views, Controllers;
- CONST minVersion = 0; maxVersion = 0;
- TYPE
- Line = POINTER TO RECORD
- next: Line;
- x0, y0, x1, y1: LONGINT
- END;
- Model = POINTER TO RECORD (Models.ModelDesc)
- lines: Line
- END;
- View = POINTER TO RECORD (Views.ViewDesc)
- color: Ports.Color;
- graph: Model
- END;
- UpdateMsg = RECORD (Models.UpdateMsg)
- l, t, r, b: LONGINT
- END;
- LineOp = POINTER TO RECORD (Domains.OperationDesc)
- graph: Model;
- line: Line
- END;
- ColorOp = POINTER TO RECORD (Domains.OperationDesc)
- view: View;
- color: Ports.Color
- END;
- PROCEDURE GetBox (x0, y0, x1, y1: LONGINT; VAR l, t, r, b: LONGINT);
- BEGIN
- IF x0 > x1 THEN l := x1; r := x0 ELSE l := x0; r := x1 END;
- IF y0 > y1 THEN t := y1; b := y0 ELSE t := y0; b := y1 END;
- INC(r, Ports.point); INC(b, Ports.point)
- END GetBox;
- PROCEDURE (op: LineOp) Do;
- VAR l: Line; msg: UpdateMsg;
- BEGIN
- l := op.line;
- IF l # op.graph.lines THEN (* insert op.line *)
- ASSERT(l # NIL, 100); ASSERT(l.next = op.graph.lines, 101);
- op.graph.lines := l
- ELSE (* delete op.line *)
- ASSERT(l = op.graph.lines, 102);
- op.graph.lines := l.next
- END;
- GetBox(l.x0, l.y0, l.x1, l.y1, msg.l, msg.t, msg.r, msg.b); Models.Broadcast(op.graph, msg)
- END Do;
- PROCEDURE (m: Model) Internalize (VAR rd: Stores.Reader);
- VAR thisVersion: SHORTINT; x0: LONGINT; p: Line;
- BEGIN
- m.Internalize^(rd);
- IF ~rd.cancelled THEN
- rd.ReadVersion(minVersion, maxVersion, thisVersion);
- IF ~rd.cancelled THEN
- rd.ReadLInt(x0); m.lines := NIL;
- WHILE x0 # MIN(LONGINT) DO
- NEW(p); p.next := m.lines; m.lines := p;
- p.x0 := x0; rd.ReadLInt(p.y0); rd.ReadLInt(p.x1); rd.ReadLInt(p.y1);
- rd.ReadLInt(x0)
- END
- END
- END
- END Internalize;
- PROCEDURE (m: Model) Externalize (VAR wr: Stores.Writer);
- VAR p: Line;
- BEGIN
- m.Externalize^(wr);
- wr.WriteVersion(maxVersion);
- p := m.lines;
- WHILE p # NIL DO
- wr.WriteLInt(p.x0); wr.WriteLInt(p.y0); wr.WriteLInt(p.x1); wr.WriteLInt(p.y1);
- p := p.next
- END;
- wr.WriteLInt(MIN(LONGINT))
- END Externalize;
- PROCEDURE (m: Model) CopyAllFrom (source: Models.Model);
- BEGIN
- m.lines := source(Model).lines (* lines are immutable and thus can be shared *)
- END CopyAllFrom;
- PROCEDURE (m: Model) InitFrom (source: Models.Model); (* do nothing *)
- END InitFrom;
- PROCEDURE (m: Model) Insert (x0, y0, x1, y1: LONGINT);
- VAR op: LineOp; p: Line;
- BEGIN
- NEW(op); op.graph := m;
- NEW(p); p.next := m.lines; op.line := p;
- p.x0 := x0; p.y0 := y0; p.x1 := x1; p.y1 := y1;
- Models.Do(m, "Insert Line", op)
- END Insert;
- PROCEDURE (op: ColorOp) Do;
- VAR color: Ports.Color;
- BEGIN
- color := op.view.color; (* save old state *)
- op.view.color := op.color; (* set new state *)
- Views.Update(op.view, Views.keepFrames); (* restore everything *)
- op.color := color (* old state becomes new state for undo *)
- END Do;
- PROCEDURE (v: View) Internalize (VAR rd: Stores.Reader);
- VAR thisVersion: SHORTINT; s: Stores.Store;
- BEGIN
- v.Internalize^(rd);
- IF ~rd.cancelled THEN
- rd.ReadVersion(minVersion, maxVersion, thisVersion);
- IF ~rd.cancelled THEN
- rd.ReadLInt(v.color);
- rd.ReadStore(s); ASSERT(s # NIL, 100);
- IF s IS Model THEN
- v.InitModel(s(Model))
- ELSE
- rd.TurnIntoAlien(Stores.alienComponent)
- END
- END
- END
- END Internalize;
- PROCEDURE (v: View) Externalize (VAR wr: Stores.Writer);
- BEGIN
- v.Externalize^(wr);
- wr.WriteVersion(maxVersion);
- wr.WriteLInt(v.color);
- wr.WriteStore(v.graph)
- END Externalize;
- PROCEDURE (v: View) CopyFrom (source: Views.View);
- BEGIN
- v.CopyFrom^(source);
- WITH source: View DO
- v.color := source.color
- END
- END CopyFrom;
- PROCEDURE (v: View) InitModel (m: Models.Model);
- BEGIN
- v.graph := m(Model)
- END InitModel;
- PROCEDURE (v: View) ThisModel (): Models.Model;
- BEGIN
- RETURN v.graph
- END ThisModel;
- PROCEDURE (v: View) Restore (f: Views.Frame; l, t, r, b: LONGINT);
- VAR p: Line;
- BEGIN
- p := v.graph.lines;
- WHILE p # NIL DO
- f.DrawLine(p.x0, p.y0, p.x1, p.y1, f.dot, v.color);
- p := p.next
- END
- END Restore;
- PROCEDURE (v: View) HandleModelMsg (VAR msg: Models.Message);
- BEGIN
- WITH msg: UpdateMsg DO
- Views.UpdateIn(v, msg.l, msg.t, msg.r, msg.b, Views.keepFrames)
- ELSE
- END
- END HandleModelMsg;
- PROCEDURE (v: View) SetColor (color: Ports.Color);
- VAR op: ColorOp;
- BEGIN
- NEW(op); op.view := v; op.color := color; Views.Do(v, "Set Color", op)
- END SetColor;
- PROCEDURE (v: View) HandleCtrlMsg (f: Views.Frame; VAR msg: Controllers.Message;
- VAR focus: Views.View);
- VAR x0, y0, x1, y1, x, y, res, l, t, r, b: LONGINT; modifiers: SET; isDown: BOOLEAN;
- BEGIN
- WITH msg: Controllers.TrackMsg DO
- x0 := msg.x; y0 := msg.y; x1 := x0; y1 := y0;
- f.SaveRect(f.l, f.t, f.r, f.b, res); (* operation was successful if res = 0 *)
- IF res = 0 THEN f.DrawLine(x0, y0, x1, y1, Ports.point, v.color) END;
- REPEAT
- f.Input(x, y, modifiers, isDown);
- IF (x # x1) OR (y # y1) THEN
- GetBox(x0, y0, x1, y1, l, t, r, b); f.RestoreRect(l, t, r, b, Ports.keepBuffer);
- x1 := x; y1 := y;
- IF res = 0 THEN f.DrawLine(x0, y0, x1, y1, Ports.point, v.color) END
- END
- UNTIL ~isDown;
- GetBox(x0, y0, x1, y1, l, t, r, b); f.RestoreRect(l, t, r, b, Ports.disposeBuffer);
- v.graph.Insert(x0, y0, x1, y1)
- | msg: Controllers.EditMsg DO
- IF msg.op = Controllers.pasteChar THEN
- CASE msg.char OF
- | "B": v.SetColor(Ports.black)
- | "r": v.SetColor(Ports.red)
- | "g": v.SetColor(Ports.green)
- | "b": v.SetColor(Ports.blue)
- ELSE
- END
- END
- ELSE
- END
- END HandleCtrlMsg;
- PROCEDURE Deposit*;
- VAR m: Model; v: View;
- BEGIN
- NEW(m);
- NEW(v); v.InitModel(m);
- Views.Deposit(v)
- END Deposit;
- END ObxLines.
- TextControllers.StdCtrlDesc
- TextControllers.ControllerDesc
- Containers.ControllerDesc
- Controllers.ControllerDesc
- TextRulers.StdRulerDesc
- TextRulers.RulerDesc
- TextRulers.StdStyleDesc
- TextRulers.StyleDesc
- TextRulers.AttributesDesc
- Helvetica
- Documents.ControllerDesc
-